package com.libraries.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ScrollView;

public class VScrollView extends ScrollView {
//	private GestureDetector mGestureDetector;
	// 滑动距离及坐标  
    private float xDistance, yDistance, xLast, yLast;  
	public VScrollView(Context context, AttributeSet attrs) {
		super(context, attrs);
//		mGestureDetector = new GestureDetector(context, new YScrollDetector());
	}

	@Override  
    public boolean onInterceptTouchEvent(MotionEvent ev) {  
        switch (ev.getAction()) {  
            case MotionEvent.ACTION_DOWN:  
                xDistance = yDistance = 0f;  
                xLast = ev.getX();  
                yLast = ev.getY();  
                break;  
            case MotionEvent.ACTION_MOVE:  
                final float curX = ev.getX();  
                final float curY = ev.getY();  
                  
                xDistance += Math.abs(curX - xLast);  
                yDistance += Math.abs(curY - yLast);  
                xLast = curX;  
                yLast = curY;  
                  
                if(xDistance > yDistance){  
                    return false;  
                }    
        }  
  
        return super.onInterceptTouchEvent(ev);  
    }  

//	class YScrollDetector extends SimpleOnGestureListener {
//
//		@Override
//		public boolean onScroll(MotionEvent e1, MotionEvent e2,
//				float distanceX, float distanceY) {
//			/**
//			 * 如果我们滚动更接近水平方向,返回false,让子视图来处理它
//			 */
//			return (Math.abs(distanceY) > Math.abs(distanceX));
//		}
//	}
}
